using System;
using System.Collections.Generic;
using System.Text;
using Xeml.Document;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Diagnostics;

namespace Xeml.Visualization
{
    public class VisObserverPoint : VisualTimeElement
    {
        private ObservationPoint observationPoint;

        public override TimeSpan Time
        {
            get
            {
                return this.observationPoint.TimePoint;
            }
            set
            {
                this.observationPoint.TimePoint = value;
            }
        }

       
        public ObservationPoint ObservationPoint
        {
            get { return observationPoint; }
        }

        public VisObserverPoint(ObservationPoint op, float x, float y, SizeF size)
        {
            this.observationPoint = op;
            this.x = x;
            this.y = y;
            this.Size = size;
            this.observationPoint.TimePointHasChanged += new EventHandler<Mpi.Common.PropertyHasChangedEventArgs<TimeSpan>>(observationPoint_TimePointChanged);       
        }

        void observationPoint_TimePointChanged(object sender, Mpi.Common.PropertyHasChangedEventArgs<TimeSpan> e)
        {
            OnXLocationUpdateNeeded(e);
        }

        protected override void SetShape()
        {
            RectangleF bounds = new RectangleF();
            bounds.Size = this.size;
            bounds.X = this.x - (this.size.Width / 2f);
            bounds.Y = this.y - this.size.Height;
            this.shape = RectToTriangle(bounds);
        }

      

        private GraphicsPath RectToTriangle(RectangleF rect)
        {
            GraphicsPath ret = new GraphicsPath();
            ret.StartFigure();
            ret.AddLine(rect.Left, rect.Top, rect.Left + (rect.Width / 2), rect.Bottom);
            ret.AddLine(rect.Left + (rect.Width / 2), rect.Bottom, rect.Right, rect.Top);
            ret.CloseFigure();
            return ret;

        }

       


       
    }
}
